{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Assign Cookies"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #greedy #array #two-pointers #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #贪心 #数组 #双指针 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findContentChildren"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #分发饼干"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>假设你是一位很棒的家长，想要给你的孩子们一些小饼干。但是，每个孩子最多只能给一块饼干。</p>\n",
    "\n",
    "<p>对每个孩子 <code>i</code>，都有一个胃口值 <code>g[i]</code><sub>，</sub>这是能让孩子们满足胃口的饼干的最小尺寸；并且每块饼干 <code>j</code>，都有一个尺寸 <code>s[j]</code><sub> </sub>。如果 <code>s[j] >= g[i]</code>，我们可以将这个饼干 <code>j</code> 分配给孩子 <code>i</code> ，这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子，并输出这个最大数值。</p>\n",
    " \n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> g = [1,2,3], s = [1,1]\n",
    "<strong>输出:</strong> 1\n",
    "<strong>解释:</strong> \n",
    "你有三个孩子和两块小饼干，3个孩子的胃口值分别是：1,2,3。\n",
    "虽然你有两块小饼干，由于他们的尺寸都是1，你只能让胃口值是1的孩子满足。\n",
    "所以你应该输出1。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> g = [1,2], s = [1,2,3]\n",
    "<strong>输出:</strong> 2\n",
    "<strong>解释:</strong> \n",
    "你有两个孩子和三块小饼干，2个孩子的胃口值分别是1,2。\n",
    "你拥有的饼干数量和尺寸都足以让所有孩子满足。\n",
    "所以你应该输出2.\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= g.length <= 3 * 10<sup>4</sup></code></li>\n",
    "\t<li><code>0 <= s.length <= 3 * 10<sup>4</sup></code></li>\n",
    "\t<li><code>1 <= g[i], s[j] <= 2<sup>31</sup> - 1</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [assign-cookies](https://leetcode.cn/problems/assign-cookies/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [assign-cookies](https://leetcode.cn/problems/assign-cookies/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3]\\n[1,1]', '[1,2]\\n[1,2,3]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        child = cookie = 0\n",
    "        while child < len(g) and cookie < len(s):\n",
    "            if g[child] <= s[cookie]:\n",
    "                child += 1\n",
    "            cookie += 1\n",
    "        return child"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g, s):\n",
    "        \"\"\"\n",
    "        :type g: List[int]\n",
    "        :type s: List[int]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        res = 0\n",
    "        while(len(g) != 0 and len(s) != 0):\n",
    "            if(g[0] <= s[0]):\n",
    "                s.pop(0)\n",
    "                g.pop(0)\n",
    "                res += 1\n",
    "            else:\n",
    "                s.pop(0)\n",
    "        \n",
    "        return(res)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g, s):\n",
    "        \"\"\"\n",
    "        :type g: List[int]\n",
    "        :type s: List[int]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        \n",
    "        if not g or not s:\n",
    "            return 0\n",
    "        \n",
    "        \n",
    "        g.sort(reverse=True)\n",
    "        s.sort(reverse=True)\n",
    "        \n",
    "\n",
    "        len1,len2=len(g),len(s)\n",
    "        i=0\n",
    "        \n",
    "        \n",
    "        for each in g:\n",
    "            if each<=s[i]:\n",
    "                i+=1\n",
    "            if i==len2:\n",
    "                break\n",
    "        return i\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g, s):\n",
    "        \"\"\"\n",
    "        :type g: List[int]\n",
    "        :type s: List[int]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        if len(g) <= 0 or len(s) <= 0:\n",
    "            return 0\n",
    "        g1 = 0\n",
    "        s1 = 0\n",
    "        g = sorted(g)\n",
    "        s = sorted(s)\n",
    "        while g1 < len(g) and s1 < len(s):\n",
    "            if g[g1] <= s[s1]:\n",
    "                g1 += 1\n",
    "            s1 += 1\n",
    "        return g1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: 'List[int]', s: 'List[int]') -> 'int':\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        print(g)\n",
    "        res = 0\n",
    "        i,j = 0 , 0\n",
    "        while i < len(g) and j < len(s):\n",
    "            if g[i] <= s[j]:\n",
    "                i+=1\n",
    "                j+=1\n",
    "                res+=1\n",
    "            else:\n",
    "                j+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g, s):\n",
    "        \"\"\"\n",
    "        :type g: List[int]\n",
    "        :type s: List[int]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        count = 0\n",
    "        kids = sorted(g)\n",
    "        cookies = sorted(s)\n",
    "\n",
    "        for sj in cookies:\n",
    "            judge = [True if gi <= sj else False for gi in kids]\n",
    "            if True in judge:\n",
    "                del kids[judge.index(True)]\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        s.sort()\n",
    "        g.sort()\n",
    "        count,i,j = (0,0,0)\n",
    "        while(i < len(s) and j < len(g)):\n",
    "            if s[i] >= g[j]:\n",
    "                count += 1\n",
    "                j += 1\n",
    "            i += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g = sorted(g)\n",
    "        s = sorted(s)\n",
    "        z = 0\n",
    "        indx = 0\n",
    "        for ele in s:\n",
    "            if indx < len(g) and ele >= g[indx] :\n",
    "                z += 1\n",
    "                indx +=1 \n",
    "        return z \n",
    "    \n",
    "    \n",
    "s =Solution() \n",
    "g =s.findContentChildren([1,2,3],[1,1])\n",
    "print(g)    \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: 'List[int]', s: 'List[int]') -> 'int':\n",
    "        g = sorted(g)\n",
    "        s = sorted(s)\n",
    "        print(g, s)\n",
    "        i, j = 0, 0\n",
    "        while i < len(g) and j < len(s):\n",
    "            if s[j] >= g[i]:\n",
    "                i += 1    # 这个孩子喂饱了 去喂下一个孩子\n",
    "            j += 1\n",
    "        return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g, s):\n",
    "        dg = collections.Counter(g)\n",
    "        ds = collections.Counter(s)\n",
    "        greeds = sorted(dg.keys())\n",
    "        cookies = sorted(ds.keys())\n",
    "\n",
    "        # like set's intersection operation\n",
    "        count = 0\n",
    "        b1 = b2 = 0\n",
    "        e1 = len(greeds)\n",
    "        e2 = len(cookies)\n",
    "        while b1 < e1 and b2 < e2:\n",
    "            if greeds[b1] > cookies[b2]:\n",
    "                b2 += 1\n",
    "            else:\n",
    "                a = dg[greeds[b1]]\n",
    "                b = ds[cookies[b2]]\n",
    "                if a < b:\n",
    "                    count += a\n",
    "                    b1 += 1\n",
    "                    ds[cookies[b2]] -= a\n",
    "                elif a == b:\n",
    "                    count += a\n",
    "                    b1 += 1\n",
    "                    b2 += 1\n",
    "                else:\n",
    "                    count += b\n",
    "                    b2 += 1\n",
    "                    dg[greeds[b1]] -= b\n",
    "\n",
    "        return count\n",
    "            \n",
    "            \n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        count = 0\n",
    "        start = 0\n",
    "        for i in range(len(g)):\n",
    "            for j in range(start, len(s)):\n",
    "                if g[i] <= s[j]:\n",
    "                    count += 1\n",
    "                    s.pop(j)\n",
    "                    start = j\n",
    "                    break\n",
    "                if not s:\n",
    "                    return count\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def swap(self, g:List[int], index, index2):\n",
    "        tmp = g[index]\n",
    "        g[index] = g[index2]\n",
    "        g[index2] = tmp\n",
    "\n",
    "    # def _quick_sort(self, g:List[int], l:int, r:int) -> List[int]:\n",
    "    #\n",
    "    #     i = l\n",
    "    #     tmp = g[r]\n",
    "    #     for _ in range(l, r):\n",
    "    #         if g[_] < tmp:\n",
    "    #             if i != _:\n",
    "    #                 self.swap(g, i, _)\n",
    "    #             i = i + 1\n",
    "    #\n",
    "    #     self.swap(g, i, r)\n",
    "    #     return i\n",
    "\n",
    "    \n",
    "    def _quick_sort(self, g:List[int], l:int, r:int) -> List[int]:\n",
    "    \n",
    "        i = l\n",
    "        tmp = g[r]\n",
    "        for _ in range(l, r):\n",
    "            if g[_] < tmp:\n",
    "                if i != _:\n",
    "                    self.swap(g, i, _)\n",
    "                i = i + 1\n",
    "    \n",
    "        self.swap(g, i, r)\n",
    "        return i\n",
    "\n",
    "\n",
    "\n",
    "    def quick_sort(self, g, l, r):\n",
    "        if l < r:\n",
    "            middle = self._quick_sort(g, l, r)\n",
    "            self.quick_sort(g, l, middle-1)\n",
    "            self.quick_sort(g, middle + 1, r)\n",
    "\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        self.quick_sort(g, 0, g.__len__()-1)\n",
    "        self.quick_sort(s, 0, s.__len__() - 1)\n",
    "        result = 0\n",
    "        for _ in g:\n",
    "            if s.__len__() > 0:\n",
    "                while s.__len__() > 0:\n",
    "                    if _ <= s.pop(0):\n",
    "                        result = result + 1\n",
    "                        break\n",
    "            else:\n",
    "                break\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "\n",
    "        g.sort(reverse=True)\n",
    "        s.sort(reverse=True)\n",
    "        print(g)\n",
    "        print(s)\n",
    "        k=0\n",
    "        while s and g:\n",
    "            if s[-1] >= g[-1]:\n",
    "                s.pop()\n",
    "                g.pop()\n",
    "                k+=1\n",
    "\n",
    "            else:\n",
    "                s.pop()\n",
    "\n",
    "        return k\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        count = 0;\n",
    "        for kid in g:\n",
    "            for cookie in s:\n",
    "                if cookie >= kid:\n",
    "                    count += 1\n",
    "                    s.remove(cookie)\n",
    "                    break\n",
    "\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        count=0\n",
    "        for i in g:\n",
    "            if s:\n",
    "                for j in s:\n",
    "                    if j>=i:\n",
    "                        count+=1\n",
    "                        s.remove(j)\n",
    "                        break\n",
    "\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort(reverse=True)\n",
    "        s.sort(reverse=True)\n",
    "        num = 0\n",
    "        while g and s:\n",
    "            g1 = g.pop()\n",
    "            s1 = s.pop()\n",
    "            while s and s1 < g1:\n",
    "                s1 = s.pop()\n",
    "            if s or (not s and s1 >= g1):\n",
    "                num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort(reverse = True)\n",
    "        s.sort(reverse = True)\n",
    "        count = 0\n",
    "        while len(g) > 0 and len(s) > 0:\n",
    "            g_tem = g.pop(-1)\n",
    "            j = len(s) - 1\n",
    "            found = False\n",
    "            while j >= 0:\n",
    "                if s[j] >= g_tem:\n",
    "                    s.pop(j)\n",
    "                    count += 1\n",
    "                    found = True\n",
    "                    break\n",
    "                else:\n",
    "                    j -= 1\n",
    "            if found:\n",
    "                pass\n",
    "            else:\n",
    "                break\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        sorted_g = sorted(g)\n",
    "        sorted_s = sorted(s)\n",
    "        res = 0\n",
    "        m, n = len(sorted_g), len(sorted_s)\n",
    "        for user in sorted_g:\n",
    "            for item in sorted_s:\n",
    "                if item >= user:\n",
    "                    res += 1\n",
    "                    sorted_s.remove(item)\n",
    "                    break\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        number, j = 0, -1\n",
    "        for i in range(-1, -(len(g)+1), -1):\n",
    "            if len(s)<abs(j):\n",
    "                return number\n",
    "            if s[j] >= g[i]:\n",
    "                number += 1\n",
    "                j -= 1\n",
    "        return number\n",
    "\n",
    "\n",
    "        # n = 0\n",
    "        # def compare(g,s,n):\n",
    "        #     if len(s) == 0:\n",
    "        #         return n\n",
    "        #     elif len(g) == 0:\n",
    "        #         return n\n",
    "        #     else:\n",
    "        #         number = 0\n",
    "        #         for i in range(-1,-(len(s)+1),-1):\n",
    "        #             if s[i] >= g[-1]:\n",
    "        #                 number += 1\n",
    "        #         n = n+number\n",
    "        #         if number == 0:\n",
    "        #             return compare(g[-1-1::-1],s[-1-number::-1],n)\n",
    "        #         else:\n",
    "        #             return compare(g[-1-number::-1],s[-1-number::-1],n)\n",
    "        # compare(g,s,n)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        g.reverse()\n",
    "        s.sort()\n",
    "        count = 0\n",
    "        while len(s) > 0 and len(g) > 0:\n",
    "            p = s[0]\n",
    "            for i in range(len(g)):\n",
    "                if g[i] <= p:\n",
    "                    count += 1\n",
    "                    g.pop(i)\n",
    "                    break\n",
    "            s.pop(0)\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        if not g:\n",
    "            return 0\n",
    "        g.sort(reverse=True)\n",
    "        s.sort(reverse=True)\n",
    "        res = 0\n",
    "        target = g.pop()\n",
    "        while s:\n",
    "            if s[-1] >= target:\n",
    "                s.pop()\n",
    "                res +=1\n",
    "                if not g:\n",
    "                    break\n",
    "                target = g.pop()\n",
    "            else:\n",
    "                s.pop()\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        r=0\n",
    "        while g and s:\n",
    "            a=max(g)\n",
    "            b=max(s)\n",
    "            if a<=b:\n",
    "                g.remove(a)\n",
    "                s.remove(b)\n",
    "                r+=1\n",
    "            else:\n",
    "                g.remove(a)\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        if len(s) == 0:\n",
    "            return 0\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        result = 0\n",
    "        for content in g:\n",
    "            while len(s) > 0:\n",
    "                if s[0] < content:\n",
    "                    s.pop(0)\n",
    "                else:\n",
    "                    result += 1\n",
    "                    s.pop(0)\n",
    "                    break\n",
    "            if len(s) == 0:\n",
    "                return result\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        ans=0\n",
    "        while len(s) and len(g):\n",
    "            if s[0]>=g[0]:\n",
    "                ans+=1\n",
    "                s.pop(0)\n",
    "                g.pop(0)\n",
    "            else:\n",
    "                s.pop(0)\n",
    "        return  ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        count = 0\n",
    "        for i in g:\n",
    "            for j in s:\n",
    "                if j >= i:\n",
    "                    count += 1\n",
    "                    s.remove(j)\n",
    "                    break\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        a = 0\n",
    "        i,j = 0,0\n",
    "        while i < len(g) and j < len(s):\n",
    "            if s[j] < g[i]:\n",
    "                j += 1\n",
    "                continue\n",
    "            if s[j] >= g[i]:\n",
    "                i += 1\n",
    "                j += 1\n",
    "                a += 1\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        indg,inds = len(g)-1, len(s)-1\n",
    "        #if inds<=0: return 0\n",
    "        g=sorted(g)\n",
    "        s=sorted(s)\n",
    "        n=0\n",
    "        while (indg>=0 and inds>=0):\n",
    "            #print(indg,inds)\n",
    "            if g[indg]<=s[inds]:\n",
    "                n+=1\n",
    "                \n",
    "                inds-=1\n",
    "            indg-=1\n",
    "        return n \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        cnt=0\n",
    "        for i in g:\n",
    "            for j in s:\n",
    "                if j>=i:\n",
    "                    cnt+=1\n",
    "                    s.remove(j)\n",
    "                    break\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        counts=0\n",
    "        tag=-1\n",
    "        for i in g:\n",
    "            for y,j in enumerate(s):\n",
    "                if j>=i:\n",
    "                    counts+=1\n",
    "                    s[y]=0\n",
    "                    break\n",
    "                \n",
    "        \n",
    "        return counts\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        gindex=0\n",
    "        sindex=0\n",
    "        res=0\n",
    "        while gindex<len(g) and sindex<len(s):\n",
    "            if g[gindex]<=s[sindex]:\n",
    "                gindex+=1\n",
    "                sindex+=1\n",
    "                res+=1\n",
    "            else:\n",
    "                sindex+=1\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findContentChildren(self, g: List[int], s: List[int]) -> int:\n",
    "        g.sort()\n",
    "        s.sort()\n",
    "        p, q = 0, 0\n",
    "        count = 0\n",
    "        while p < len(g) and q < len(s):\n",
    "            if g[p] <= s[q]:\n",
    "                p += 1\n",
    "                q += 1\n",
    "                count += 1\n",
    "            else:\n",
    "                q += 1\n",
    "        return count\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
